﻿using System.Text;

namespace JustMetClient.Models.StrategyModels
{
    public class StrategyTaskModel
    {
        /// <summary>
        /// 策略任务运行状态
        /// </summary>
        public StrategyTaskStatus Status { get; set; }
        /// <summary>
        /// 是否通过web接口反馈结果
        /// </summary>
        public bool WebApiFeedback { get; set; }
        /// <summary>
        /// 策略内容
        /// </summary>
        public StrategyModel Strategy { get; set; }
        /// <summary>
        /// 运行结果
        /// </summary>
        public ResultModel Result { get; set; }
        /// <summary>
        /// 任务描述信息
        /// </summary>
        public StrategyDescModel Desc { get; set; }

        /// <summary>
        /// 策略转换为任务
        /// </summary>
        /// <param name="strategy"></param>
        /// <returns></returns>
        public static StrategyTaskModel Model2Task(StrategyModel model)
        {
            StrategyTaskModel task = new StrategyTaskModel()
            {
                Status = StrategyTaskStatus.初始化,
                WebApiFeedback = false,
                Strategy = model,
                Result = null,
                Desc = new StrategyDescModel()
                {
                    Trigger = model.Trigger,
                    Violate = false,
                    Level = model.Event?.Name,
                    Respond = model.Event?.GetDispose(),
                }
            };
            return task;
        }
    }
}
